<template>
	<view>
		<image class="banner" :src="info.image" mode="aspectFill"></image>
		<view class="info">
			<view class="title">
				{{info.goods_name}}
			</view>
			<view class="bottom">
				<view class="score">
					<text> {{info.price}}</text>积分
				</view>
				<view class="">
					销量 {{info.stock}}
				</view>
			</view>
		</view>
		<view class="wrap">
			<view class="good_title">
				商品详情
			</view>
			<rich-text :nodes="info.goods_content"></rich-text>
		</view>
		<view class="submit">
			<view class="submitBtn" @click="exchange">
				立即兑换
			</view>
		</view>
		<view class="seat"></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				goods_no: "",
				cost: 0,
				info: {}
			}
		},
		onLoad(option) {
			this.goods_no = option.goods_no
			this.getInfo()
		},
		methods: {
			getInfo() {
				this.$post("/goods/goods", {
					goods_no: this.goods_no
				}).then(res => {
					this.info = res.data
				})
			},
			exchange() {
				let that = this
				uni.showModal({
					title:"操作确认",
					content:"确定花费"+that.info.price+"积分兑换这件商品？",
					success: function (res) {
						if(res.confirm)
						{
							console.log("用户点击了确认")
							that.$post("/user/exchange", {
								goods_no: that.goods_no
							}).then(res => {
								// that.info = res.data
								that.$toast(res.msg)
								setTimeout(function(){
									uni.navigateBack()
								},500)
							})
						}else if(res.cancel){
							console.log("用户点击了取消")
						}
					}
				});
				
				
				
			}
		}
	}
</script>

<style lang="scss">
	.banner {
		height: 680rpx;
	}

	.info {
		padding: 30rpx 40rpx;

		.title {
			font-size: 36rpx;
			margin-bottom: 30rpx;
		}

		.bottom {
			display: flex;
			align-items: center;
			justify-content: space-between;
			font-size: 24rpx;
			color: #7c7c7c;

			.score {
				color: #FF3D3D;

				text {
					font-weight: bold;
					font-size: 48rpx;
				}
			}
		}
	}

	.good_title {
		border-top: 1rpx solid #eee;
		position: relative;
		font-size: 32rpx;
		padding: 40rpx;

		&::before {
			content: "";
			width: 10rpx;
			height: 32rpx;
			background: #3670F6;
			border-radius: 5rpx;
			position: absolute;
			left: 0%;
			top: 50%;
			transform: translateY(-50%);
		}
	}

	.submit {
		background-color: #fff;
		padding: 20rpx 40rpx;
		position: fixed;
		width: 100%;
		bottom: 0;
	}

	.seat {
		height: 130rpx;
	}
</style>